package cn.yitun.chat.yitunserverimcore.general.main.push.user;

import cn.yitun.chat.yituncommonmessage.push.PushMessage;
import cn.yitun.chat.yitunservercommonlib.constant.ActionTypeConstant;
import cn.yitun.chat.yitunservercommonlib.enums.control.push.user.PersonalPushMethodEnum;
import cn.yitun.chat.yitunserverimcore.bridge.net.WriteHandler;
import cn.yitun.chat.yitunserverimcore.general.common.util.PushMessageBuild;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 用户个人相关信息推送
 * @author yitun
 * @since 1.1
 */
@Service
public class PersonalPush {
	//1.1.001
	final String action = ActionTypeConstant.PERSONAL_ACTION_PUSH;

	@Resource
	WriteHandler writeHandler;

	/**
	 * 更新详情
	 * @param key
	 * @param userId
	 */
	public void pushUpdate(Long key, Long userId) {
		String method = PersonalPushMethodEnum.UPDATE_INFO.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		// message.bodyPut("userId", userId);
		writeHandler.push(userId.toString(), message);
	}

	/**
	 * 更新密码
	 * @param key
	 * @param userId
	 */
	public void pushUpdatePassword(Long key, Long userId) {
		String method = PersonalPushMethodEnum.UPDATE_PASSWORD.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("userId", userId);
		writeHandler.push(userId.toString(), message);
	}

	/**
	 * 更新头像
	 * @param key
	 * @param userId
	 */
	public void pushUpdateHead(Long key, Long userId) {
		String method = PersonalPushMethodEnum.UPDATE_HEAD.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		// message.bodyPut("userId", userId);
		writeHandler.push(userId.toString(), message);
	}

	/**
	 * 更新验签信息
	 * @param key
	 * @param userId
	 * @param signature
	 */
	public void pushUpdateSignature(Long key, Long userId, String signature) {
		String method = PersonalPushMethodEnum.UPDATE_SIGNATURE.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("signature", signature);
		writeHandler.push(userId, message);
	}

	/**
	 * 更新状态
	 * @param key
	 * @param userId
	 * @param chatOnLine
	 */
	public void pushUpdateChatOnlineStatus(Long key, Long userId, String chatOnLine) {
		String method = PersonalPushMethodEnum.UPDATE_STATUS.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("chatOnLine", chatOnLine);
		writeHandler.push(userId, message);
	}
}
